#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <vector>

std::vector<int> split(std::string s) {
    std::vector<int> result;
    int len = s.size(), pointer = 0, n = 0;
    while (pointer < len) {
        while (!isdigit(s[pointer])) {
            ++pointer;
            if (pointer >= len) {
                break;
            }
        }
        bool havedig = false;
        while (isdigit(s[pointer])) {
            n = (n << 3) + (n << 1) + (s[pointer] ^ '0');
            havedig = true;
            ++pointer;
        }
        if (havedig) {
            result.push_back(n);
            n = 0;
        }
    }
    return result;
}

int findEl(std::vector<int> in, int l, int r, int el) {
    for (int i = l; i <= r; ++i) {
        if (in[i] == el) {
            return i;
        }
    }
    return -1;
}

void beford(std::vector<int> in, int inl, int inr, std::vector<int> after, int aftl, int aftr){
    if (inr - inl >= 0) {
        std::cout << after[aftr] << " ";
        int k = findEl(in, inl, inr, after[aftr]);
        beford(in, inl, k - 1, after, aftl, aftl + (k - inl) - 1);
        beford(in, k + 1, inr, after, aftr - (inr - k), aftr - 1);
    }
} 

int main(int argc, char *argv[]) {
    std::string inord, aftord;
    std::getline(std::cin, inord);
    std::getline(std::cin, aftord);
    std::vector<int> in = split(inord), aft = split(aftord);
    beford(in, 0, in.size() - 1, aft, 0, aft.size() - 1);
    return 0;
}
